package com.ghn.cocknovel.ui.activity.map

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.example.basemodel.base.BaseFragment
import com.ghn.cocknovel.BR
import com.ghn.cocknovel.R
import com.ghn.cocknovel.databinding.FragmentFulllistBinding
import com.ghn.cocknovel.ext.MappageLoadBase
import com.ghn.cocknovel.ui.activity.map.vm.MapViewModel
import com.kt.NetworkModel.bean.BQueryDriverTransitOrderListBean


class FulllistFragment(val mTaskid:String) : BaseFragment<FragmentFulllistBinding, MapViewModel>() {
    val mWorkAdapter by lazy { MapPassengerAdapter() }
    override fun initVariableId(): Int {
        return BR.mode
    }

    override fun initContentView(
        inflater: LayoutInflater?,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): Int {
        return R.layout.fragment_fulllist
    }

    override fun initParam() {

    }

    override fun initViewObservable() {
        viewModel?.queryTransitOrder()
        viewModel?.queryPassengerBySite?.observe(this) {
            viewModel?.AllsqueryDriverTransitOrderList(it?.siteId.toString(), mTaskid)
        }
        viewModel?.allqueryDriverTransitOrderList?.observe(this) {
            MappageLoadBase(it, mWorkAdapter)
        }
        mWorkAdapter.bindToRecyclerView(binding?.fulllistrecyclerview)
    }
    inner class MapPassengerAdapter : BaseQuickAdapter<BQueryDriverTransitOrderListBean, BaseViewHolder>,
        BaseQuickAdapter.OnItemChildClickListener, BaseQuickAdapter.OnItemClickListener {
        constructor() : super(R.layout.item_home, null) {
            onItemChildClickListener = this
            onItemClickListener = this
        }

        @SuppressLint("ResourceType")
        override fun convert(helper: BaseViewHolder?, item: BQueryDriverTransitOrderListBean?) {
            helper?.setText(R.id.item_home_author, item?.mobileLastFour)
            helper?.setText(R.id.item_home_author, "尾号"+item?.mobileLastFour)
            helper?.setText(R.id.item_home_originAddress,item?.originAddress)
            helper?.setText(R.id.item_home_destinationAddress,item?.destinationAddress)
            helper?.setText(R.id.item_home_PassengerNumber,"成人"+item?.adultNum+"人,"+"儿童"+item?.childrenNum+"人")
            when (item?.orderStatus) {
                1 -> {
                    helper?.setText(R.id.item_home_status, "待支付")
                }

                2 -> {
                    helper?.setText(R.id.item_home_status, "待呼叫")
                }

                3 -> {
                    helper?.setText(R.id.item_home_status, "呼叫中")
                }

                4 -> {
                    helper?.setText(R.id.item_home_status, "司机已接单")
                }

                5 -> {
                    helper?.setText(R.id.item_home_status, "司机到达")
                }

                6 -> {
                    helper?.setText(R.id.item_home_status, "已上车")
                }

                7 -> {
                    helper?.setText(R.id.item_home_status, "行程结束")
                }

                8 -> {
                    helper?.setText(R.id.item_home_status, "已取消")
                }

                9 -> {
                    helper?.setText(R.id.item_home_status, "已退款")
                }
            }
            helper?.itemView?.findViewById<LinearLayout>(R.id.item_home_llybottom)?.visibility=View.GONE
        }

        override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {

        }

        override fun onItemClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {

        }
    }
}